home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Oct 90 / MacApp.Tech$ 10⁄26⁄90 / 2230-Re TWindow.BuildWind-Oct90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.4 KB  |  103 lines  |  [TEXT/GEOL]

  1. Item    5885612                         23-Oct-90        14:53PDT
  2.  
  3. From:   MACDTS                          Macintosh Developer Tech Supt
  4.  
  5. To:     SATORI                          Satori SW, Hugh Rogovy,PRT
  6.  
  7. cc:     MACAPP.TECH$                    MacApp Technical
  8.  
  9. Sub:    RE-TWindow.BuildWindowRgns bug
  10.  
  11. Chris,
  12.  
  13. Thanks for pointing this out. Yes, there does seem to be a problem with
  14. centering a window multiple times. However, the problem in not with
  15. BuildWindowRgns as you state, but with TWindow.Center. Center is smashing
  16. fContRgnInset. The change to fContRgnInset was cumulative, so that successive
  17. calls to TWindow.Center caused the window to move up and to the left more and
  18. more quickly. Your solution was to modify BuildWindowRgns to always rebuild
  19. fContRgnInset. However, this is not necessary with a correctly working
  20. TWindow.Center.
  21.  
  22. In looking over TWindow.Center, I also noticed that it didn't take into account
  23. centering to devices other than the main device (this is also true with the
  24. modified version in the MacApp bugs technote, which fixes the problem of
  25. assuming the menubar is always 20 pixels high).
  26.  
  27. I made two modifications to TWindow.Center that seems to get it working. First,
  28. I removed the instructions from "WITH globalbounds DO" to "{$POP}", inclusive;
  29. they are no longer used, and contain the code that was smashing fContRgnInset.
  30. Next, I reworked the formulas that calculate the topleft corner of the window.
  31. With a couple of other minor changes to help clean things up, the whole routine
  32. now looks like the following:
  33.  
  34. PROCEDURE TWindow.Center(horizontally, vertically, forDialog: BOOLEAN);
  35.  
  36.    VAR
  37.    windowSize: Point;
  38.    screenSize: Point;
  39.    globalbounds, screenRect: Rect;
  40.    rgnsWereBuilt:  BOOLEAN;
  41.  
  42.    BEGIN
  43.    fHorzCentered := horizontally;
  44.    fVertCentered := vertically;
  45.    IF (fWMgrWindow <> NIL) & (horizontally | vertically) THEN
  46.    BEGIN
  47.    IF GetMaxIntersectedDevice(screenRect) = NIL THEN;
  48.    WITH screenRect DO
  49.    BEGIN
  50.    screenSize.h := right - left;
  51.    screenSize.v := bottom - top;   { NOTE: GetMaxIntersectedDevice accounts
  52. for
  53.     menubar so don't subtract gMbarHeight }
  54.    END;
  55.  
  56.    rgnsWereBuilt := BuildWindowRgns(kBuild);
  57.    WITH WindowPeek(fWMgrWindow)^.strucRgn^^.rgnBBox DO
  58.    BEGIN
  59.    windowSize.h := right - left;
  60.    windowSize.v := bottom - top;
  61.    END;
  62.    IF BuildWindowRgns(rgnsWereBuilt) THEN; { discard result }
  63.  
  64.    GetGlobalBounds(globalbounds);
  65.  
  66.    WITH globalbounds DO
  67.    BEGIN
  68.    IF horizontally THEN
  69.    left := screenRect.left { left of device }
  70.    + (screenSize.h - windowSize.h) DIV 2   { total gray area left and right
  71.      of window, divided by 2. }
  72.    + fContRgnInset.h;  { offset for position of portrect (which Locate wants)
  73. }
  74.    IF vertically THEN
  75.    IF forDialog THEN
  76.    { Put it in the top third of the screen }
  77.    top := screenRect.top   { top of device }
  78.    + (screenSize.v - windowSize.v) DIV 3   { total gray area above and below
  79.      window, divided by 3. }
  80.    + fContRgnInset.v   { offset for position of portrect (which Locate wants)
  81. }
  82.    ELSE
  83.    top := screenRect.top   { top of device }
  84.    + (screenSize.v - windowSize.v) DIV 2   { total gray area above and below
  85.      window, divided by 2. }
  86.    + fContRgnInset.v;  { offset for position of portrect (which Locate wants)
  87. }
  88.    END;
  89.    Locate(globalbounds.left, globalbounds.top, kDontInvalidate);
  90.    END;
  91.    END;
  92.  
  93.  
  94. If no one finds any problems with this, I'll put it in the MacApp bugs
  95. Technote.
  96.  
  97.  
  98. - Keith Rollin
  99. - Apple Developer Technical Support
  100.  
  101.  
  102.  
  103.